<?php

include_once '../lib/studysql.php';

$db = new PGSQLConnector('u_superuser');

$universitySQL = "SELECT\n";
$universitySQL .= "org.idfaculty AS id,\n";
$universitySQL .= "org.name,\n";
$universitySQL .= "org.abbreviation\n";
$universitySQL .= "FROM vw_faculty AS org\n";
$universitySQL .= "WHERE org.idparent IS NULL AND org.countrycode = 'no' AND org.timedeleted IS NULL\n";
$universitySQL .= "ORDER BY org.abbreviation\n";
$university = $db->query2array($universitySQL);

$fieldofstudySQL = "SELECT\n";
$fieldofstudySQL .= "sf.studyfield\n";
$fieldofstudySQL .= "FROM studyfield AS sf\n";
$fieldofstudySQL .= "WHERE sf.official = 'Y' AND sf.timedeleted IS NULL\n";
$fieldofstudySQL .= "ORDER BY sf.studyfield";
$fieldofstudy = $db->query2array($fieldofstudySQL);

$yearreqRange = range(1,5);

$template = newPage('study');
$template->title = 'Study Info - IAESTE Application System';
$template->l = $l;
$template->yearreq = $yearreqRange;
$template->study = $_SESSION['study'];
$template->university = $university;
$template->studyfield = $fieldofstudy;

try {
    echo $template->execute();
} catch (Exception $e) {
    echo $e;
}
?>
